package cn.zzdt4j.config.model.biz.impl;

import cn.zzdt4j.common.constant.ConfigModifyTypeConstants;
import cn.zzdt4j.common.toolkit.BeanUtil;
import cn.zzdt4j.config.model.biz.threadpool.ConfigModifyVerifyReqDTO;
import cn.zzdt4j.config.model.biz.threadpool.ThreadPoolSaveOrUpdateReqDTO;
import cn.zzdt4j.config.service.biz.ThreadPoolService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * The type Thread pool manage config modification verify service impl.
 *
 * @author by <a href="mailto:ligang941012@gmail.com">gang.Li</a>
 * @since 2023 /11/12 21:53
 */
@Slf4j
@Service
@AllArgsConstructor
public class ThreadPoolManageConfigModificationVerifyServiceImpl extends AbstractConfigModificationVerifyService {

    private final ThreadPoolService threadPoolService;

    @Override
    protected void updateThreadPoolParameter(ConfigModifyVerifyReqDTO reqDTO) {
        final ThreadPoolSaveOrUpdateReqDTO saveOrUpdateReqDTO = BeanUtil.convert(reqDTO, ThreadPoolSaveOrUpdateReqDTO.class);
        saveOrUpdateReqDTO.setCoreSize(reqDTO.getCorePoolSize());
        saveOrUpdateReqDTO.setMaxSize(reqDTO.getMaximumPoolSize());
        threadPoolService.saveOrUpdateThreadPoolConfig(null, saveOrUpdateReqDTO);
    }

    @Override
    public Integer type() {
        return ConfigModifyTypeConstants.THREAD_POOL_MANAGER;
    }
}
